require("../../both/base.js")
require("./AdminForumCtrl.scss")

import DataTables from "../DataTabel/DataTable.jsx"

class AdminForumCtrl extends React.Component{
    constructor(props){
        super(props)

        const init = this.props.init
        init()
    }

    delItemWrap(item){
        var self = this
        const delItem = self.props.delItem
        return function(e){
            if(confirm("确认删除吗？")){
                delItem(item)
            }
        }
    }


    render(){
        let self = this

        const trs = self.props.courses.map((ele,idx) => {
            return <tr key={ele.id.toString()}>
                <td><div className="item">{ele.id}</div></td>
                <td><div className="item">{ele.title}</div></td>
                <td><div className="item">{ele.User.username}</div></td>
                <td>
                    <div className="item">
                    {
                        new Date(ele.createdAt).getUTCFullYear() + "年" +
                        (parseInt(new Date(ele.createdAt).getUTCMonth()) + 1).toString() + "月" +
                        new Date(ele.createdAt).getUTCDate() + "日"
                    }
                    </div>
                </td>
                <td>
                    <li className="dropdown">
                        <a href="#" className="dropdown-toggle" onClick={(e) => {
                            var li = e.target.parentNode
                            if(li.className === "dropdown"){
                                li.className = "dropdown open"
                            }else{
                                li.className = "dropdown"
                            }
                        }}>
                            操作列表
                            <span className="caret"></span>
                        </a>
                        <ul className="dropdown-menu">
                            <li><a href="#">删除</a></li>
                            <li><a href="#">设置为不可见</a></li>
                        </ul>
                    </li>
                </td>
            </tr>
        })

        // todo: 分页问题一直没有解决掉！
        return <div className="admin_forum_ctrl bln">
            <div className="title">
                <span>论坛管理</span>
            </div>
            <DataTables {...self.props}
                        ths={["帖子id","帖子标题","发帖人","发帖时间","操作"]}
                        searchPlaceHolder="输入文本进行查找"
                        trs={trs}
                        addDisable={true}
                        editDisable={true}
                        selectDisable={true}
                        editHref="#"
            />
        </div>
    }
}

export default AdminForumCtrl